package com.tengju.bff.interfaces.manage.common.assembler;

import com.tengju.bff.interfaces.manage.common.vo.UploadFileVO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.springframework.web.multipart.MultipartFile;

public class ImageFileAssembler {

    public static UploadFileVO ModelToVO(String url, MultipartFile multipartFile)
            throws IOException {
        UploadFileVO uploadFileVO = new UploadFileVO();
        uploadFileVO.setUrl(url);
        uploadFileVO.setContentType(multipartFile.getContentType());
        BufferedImage bufferedImage = ImageIO.read(multipartFile.getInputStream());
        if (bufferedImage != null) {
            Integer width = bufferedImage.getWidth();
            Integer height = bufferedImage.getHeight();
            uploadFileVO.setWidth(width);
            uploadFileVO.setHeight(height);
        }
        uploadFileVO.setSize(multipartFile.getSize());
        return uploadFileVO;
    }
}
